/*
 * $Id: NoGarbage.java 150 2013-01-26 14:03:56Z vladimirow@mail.ru $
 * $HeadURL: http://ultralog.googlecode.com/svn/ultralog/tags/release-0.1/src-example/java/NoGarbage.java $
 *
 * This file is a part of ultralog project (http://code.google.com/p/ultralog/).
 * Released under New BSD License.
 */

import com.google.code.ultralog.BasicLogger;
import com.google.code.ultralog.LogMessage;
import com.google.code.ultralog.LoggerManager;

/**
 * Example that demonstrates garbage-free logging.
 *
 * @author Mikhail Vladimirov
 */
public class NoGarbage
{
    /**
     * Entry point of the example.
     *
     * @param args command-line arguments
     */
    public static void main (String [] args)
    {
        MemoryLogger logger = LoggerManager.createLogger (MemoryLogger.class);

        Runtime runtime = Runtime.getRuntime ();
        while (true)
        {
            if (logger.isInfoEnabled ())
                logger.freeMemory (runtime.freeMemory ());
        }
    }

    /**
     * Logger interface that allows logging amount of free memory.
     */
    protected interface MemoryLogger extends BasicLogger
    {
        /**
         * Logs amount of free memory.
         *
         * @param freeMemory amount of free memory
         */
        @LogMessage (level = INFO, template = "Free memory: ${1}")
        void freeMemory (long freeMemory);
    }
}
